-
Notifications
You must be signed in to change notification settings - Fork 194
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reduce universe variables and other clean-ups #1805
Conversation
Lemma int_add_pred_r a b : a + int_pred b = int_pred (a + b). | ||
Proof. | ||
apply int_add_assoc. | ||
Qed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The section above was just moved to Int/Spec.v, where it fits better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! Did we ever experiment with using minimization to set globally?
I tried it, and some things fail. One big issue is that The problem with It would be easier to use minimization to (I also just realized that Spaces/Nat.v could use a similar treatment. I'll take a look later today, so let's not merge this yet.) |
We could consider making Inductive IsTrunc : nat -> Type -> Type :=
| istrunc_iscontr : forall {A:Type}, IsContr A -> IsTrunc 0 A
| istrunc_succ : forall {A:Type} {n:nat}, (forall x y:A, IsTrunc n (x = y)) -> IsTrunc (S n) A. Of course that would involve adding some constructors in places where now we can just compute. |
We would probably want to change the argument order so that the type argument can be a parameter. Otherwise its universe has more restricted cumulativity AFAICT. |
Ugh. Maybe we could make a notation that puts the arguments back in the right order. It would be nice if there were a way to indicate which arguments are indices and which are parameters that didn't require all the parameters to come before all the indices. |
@SkySkimmer Is there any chance that in the future Coq could have cumulative fixpoints? |
I haven't seen any proposed rules of how that would work. |
I tried the inductive definition of Cumulative Inductive IsTrunc_internal (A : Type@{u}) : trunc_index -> Type@{u} :=
| istrunc_iscontr : Contr_internal A -> IsTrunc_internal A minus_two
| istrunc_succ : forall {n:trunc_index}, (forall x y:A, IsTrunc_internal (x = y) n) -> IsTrunc_internal A (trunc_S n).
Existing Class IsTrunc_internal.
Notation IsTrunc n A := (IsTrunc_internal A n). It's not just that you need to apply constructors, but that you need to go backwards. For example, we define Scheme IsTrunc_internal_ind := Induction for IsTrunc_internal Sort Type.
Scheme IsTrunc_internal_rec := Minimality for IsTrunc_internal Sort Type.
Definition IsTrunc_internal_rect := IsTrunc_internal_ind.
Definition IsTrunc_unfolded (n : trunc_index) (A : Type)
:= match n with
| minus_two => Contr_internal A
| n.+1 => forall x y : A, IsTrunc n (x = y)
end.
Definition istrunc_unfold (n : trunc_index) (A : Type)
: IsTrunc n A -> IsTrunc_unfolded n A.
Proof.
intros [istr|k istr]; exact istr.
Defined.
Definition isequiv_istrunc_unfold (n : trunc_index) (A : Type)
: IsEquiv (istrunc_unfold n A).
Proof.
simple refine (Build_IsEquiv _ _ (istrunc_unfold n A) _ _ _ _).
- destruct n; constructor; assumption.
- destruct n; reflexivity.
- intros [istr|k istr]; reflexivity.
- intros [istr|k istr]; reflexivity.
Defined.
Definition equiv_istrunc_unfold (n : trunc_index) (A : Type)
:= Build_Equiv _ _ _ (isequiv_istrunc_unfold n A). I also put primes on the constructors of Definition center (A : Type) {H : Contr A} : A := @center' A (istrunc_unfold _ _ H).
Definition contr {A : Type} {H : Contr A} (y : A) : center A = y := @contr' A (istrunc_unfold _ _ H) y. But even with these, it's annoying to work with. E.g. the last result in Contractible.v needs to use that |
We could also rid of Cumulative Inductive IsTrunc_internal (A : Type@{u}) : trunc_index -> Type@{u} :=
| istrunc_iscontr : (center : A) -> (forall y : A, center = y) -> IsTrunc_internal A minus_two
| istrunc_succ : forall {n:trunc_index}, (forall x y:A, IsTrunc_internal (x = y) n) -> IsTrunc_internal A (trunc_S n). Then there would only need to be one definition of
Sure, but don't we only need to do that once? Once we've proven the relevant equivalences, we can just apply those lemmas and tactics. In general, I've come more and more to believe in the principle that whenever possible types should be canonical, not things that compute definitionally, because this makes it easier to match against them. For instance, mightn't an inductive
but if |
@mikeshulman You're probably right that with appropriate tactics, using the inductive definition would be fairly painless. But it would probably require many small changes throughout the entire library to do the conversion, so it might be a bit of work. Another observation is that with my sample code above, we essentially have both definitions. |
It seems to me that the only time we'd actually need to transfer explicitly across that equivalence would be in proving that |
@jdchristensen Are you happy with this being merged? |
No, let's not merge this yet. If the WIP on making IsTrunc inductive pans out, then the last commit here will need to be undone. Also, I plan to see if I can make similar improvements to Nat. |
…Paths" This reverts commit a53efef.
652729c
to
052fdbc
Compare
I rebased, removed the universe variables added to proofs of IsHSet, etc., removed universe variables in Empty, improved the |
I wonder if we can shadow |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thank you very much for all this careful work!
When dealing with types defined to land in
Set
(akaType0
), such asabgroup_Z
,Pos
,Int
andFin n
, it makes sense to useLocal Set Universe Minimization ToSet.
as otherwise free universe variables are created that are not matched when using the results. By doing this and being careful to usesimple_induction
, many universe variables are eliminated. For example,abgroup_Z
goes from 25 to 0,fsucc_mod
goes from 9 to 0, andstratified_succ
goes from 17 to 1.There are other improvements mixed in, such as making use of
nat_iter
. I also cleaned up various comments and fixed indentation.